<style scoped lang='less'>
    .holiday-list-mian {
        .action-cell {
            margin-bottom: 20px;
        }

        .home-list .search-block {
            display: flex;
            margin-bottom: 10px;
        }

        .input-search {
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .home-list .selected-search {
            height: 200px;
            width: 100%;
            position: relative;
            border-radius: 4px;
            margin-bottom: 10px;

        }

        .home-list .selected-search .search-action {
            position: absolute;
            top: 10px;
            left: 10px;
            right: 10px;
        }

        .home-list .selected-search .selected-arr {
            position: absolute;
            top: 50px;
            left: 20px;
            right: 20px;
            bottom: 10px;
            overflow: scroll;
        }

        .home-list .select-click {
            border: 1px solid #dddee1;
            border-radius: 4px;
            padding: 10px;
            font-weight: 500;
            text-align: center;
            width: 260px;
            margin-bottom: 10px;
        }

        .home-list .selected-search .selected-arr .selected-item {
            /*border-bottom: 1px solid #dfdfdf;*/
            margin-bottom: 10px;
            font-size: 15px;
        }
    }

</style>
<template>
    <div class="holiday-list-mian">
        <h4>我的申请记录</h4>
        <Alert show-icon>
            此处用于显示的当前登录用户的用车申请。
        </Alert>
        <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>


    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import {Modal} from 'view-design';
    import selectSearch from '../../components/selectSearch';


    export default {
        data() {
            return {
                //审核
                formValidate: {
                    checkState: 'true',
                    reason: '',
                    gateInfos: '',
                    crossType: '',
                    startDate: '',
                    endDate: '',
                },
                geteListArr: [],
                ruleValidate: {},
                checkRow: '',
                //选择部门
                reqpeopleDept: '',
                //表格数据
                self: this,
                tableData: [],
                total: 0,
                current: 1,
                tableColumns: [
                    {
                        title: '申请人',
                        key: 'Displayname',
                        align: 'center',
                    },
                    {
                        title: '用车原因',
                        key: 'Reason',
                        align: 'center',
                    },
                    {
                        title: '用车用途',
                        key: 'CaruseType',
                        align: 'center',
                    },
                    {
                        title: '开始日期',
                        key: 'Startdate',
                        align: 'center',
                    },
                    {
                        title: '返回日期',
                        key: 'Enddate',
                        align: 'center',
                    },
                    {
                        title: '审核状态',
                        key: 'State',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            if(params.row.State == '待审批') {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'error',
                                            size: 'small'
                                        },
                                        style: {
                                            // background: '#e4e4e4',
                                            // border: '1px solid #d5d5d5',
                                            // 'margin-bottom':'10px',
                                        },
                                        on: {
                                            click: () => {
                                                this.cancelApply(params.row)
                                            }
                                        }
                                    }, '取消用车申请'),
                                ])
                            }
                        }
                    }
                ]
            }
        },
        mounted() {
            let that = this;
            this.mockTableData();
        },
        components: {
            selectSearch
        },
        watch: {
            nextName: function (newVale, oldVale) {
                if (newVale != oldVale) {
                    this.searchNext(newVale);
                }
            }
        },
        component: {
            Modal
        },
        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },

            mockTableData() {
                let that = this;

                let para = {
                    creatorId: sessionStorage.getItem('userId'),
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.MyCarUseRequest, para, function (res) {
                    that.$Loading.finish();
                    that.tableData = res.Msg;
                });
            },
            //取消用车申请
            cancelApply:function (row) {

                let that = this;


                this.$Modal.confirm({
                    title: '提示',
                    content: `确认取消该用车申请吗?`,
                    onOk: function () {
                        let para = {
                            requestId: row.Id,
                        }
                        let params = that.$qs.stringify(para);

                        this.$Loading.start();

                        apiUtil.post(that, apiUtil.urls.CancelCarUseRequest, params, function (res) {
                            that.$Loading.finish();

                            that.mockTableData();

                        });
                    }
                })


            }
        },
    }
</script>
